package org.gruposp2p.aula.gwt.client.content.coursegroup;

import org.gruposp2p.aula.gwt.client.AulaApplication;
import org.gruposp2p.aula.gwt.client.AulaConstants;
import org.gruposp2p.aula.gwt.client.event.AulaEventBus;
import org.gruposp2p.aula.gwt.client.event.CoursegroupChangeEvent;
import org.gruposp2p.aula.gwt.client.event.CoursegroupChangeHandler;
import org.gruposp2p.aula.gwt.client.model.Coursegroup;

import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.i18n.client.Constants;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

public class CoursegroupSubjectsPanel extends VerticalPanel 
implements CoursegroupChangeHandler {
	
	private AulaApplication aulaApplication;
	private AulaConstants constants;
	private TextBox nameTextBox;
	private TextBox descriptionTextBox;
    private ListBox subjectsListBox;
    private HorizontalPanel containerPanel;
    private VerticalPanel formDataPanel;    
    
	public static interface CwConstants extends Constants {	
		String SubjectNameTextBoxLabel();
		String SubjectDescripionTextBoxLabel();
		String SubjectsListLabel();
	}
	
	public CoursegroupSubjectsPanel (AulaApplication aulaApplication) {
		this.aulaApplication = aulaApplication;
		this.constants = aulaApplication.getConstants();
		containerPanel = new HorizontalPanel();

		subjectsListBox = new ListBox(true);
	    HTML subjectsListLabel = new HTML(constants.SubjectsListLabel());
	    //subjectsListBox.setStyleName("StudentPanelWidgetStudentsListLabel");
	    //subjectsListBox.ensureDebugId("cwListBox-multiBox");
	    subjectsListBox.setWidth("13em");
	    subjectsListBox.setVisibleItemCount(10);
	    VerticalPanel subjectsListBoxPanel = new VerticalPanel();
	    subjectsListBoxPanel.setSpacing(4);
	    subjectsListBoxPanel.add(subjectsListLabel);
	    subjectsListBoxPanel.add(subjectsListBox);
	    containerPanel.add(subjectsListBoxPanel);
	    // Add a handler to handle drop box events
	    subjectsListBox.addChangeHandler(new ChangeHandler() {
	      public void onChange(ChangeEvent event) {
	    	  //showStudent(studentsListBox);
	      }
	    });
		
		
		add(new Label(constants.SubjectNameTextBoxLabel()));
	    nameTextBox = new TextBox ();
	    add(nameTextBox);

	    add(new Label(constants.NewStudentDialogBoxDescriptionLabel()));
	    descriptionTextBox = new TextBox();
	    add(descriptionTextBox);

	    Button acceptButton = new Button(constants.AcceptButtonCaption(),
	    		new ClickHandler() {
		        	public void onClick(ClickEvent event) {		        	  

		        	}
		        });

	    HorizontalPanel hPanel = new HorizontalPanel();
	    hPanel.setSpacing(5);
	    hPanel.setWidth("200");
	    hPanel.add(acceptButton);
	    hPanel.setCellHorizontalAlignment(acceptButton, HorizontalPanel.ALIGN_RIGHT);
	    
	    add(hPanel);

	    //To solve Firefox strange effect
	    nameTextBox.setFocus(true);		
	    setStylePrimaryName("tabbedForm");
		AulaEventBus.getInstance().registerToCoursegroupChange(this);
	}		

	private void setCoursegroup (Coursegroup coursegroup) {
		//coursegroup.get
	}
	
	private void setSubjectFormData () {
		
	}
	
	@Override
	public void processCoursegroup(CoursegroupChangeEvent event) {
		setCoursegroup(event.getCoursegroup());
	}

}